package org.grow.infru.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.base.MoreObjects;
import lombok.Data;

import javax.persistence.*;
import java.io.Serializable;

/**
 * @Author: xwg
 * @CreateDate: 2022/2/18
 */

@Entity
@Data
public class HolyDetail implements Serializable {

    @EmbeddedId
    private HolyDetailId holyDetailId;
    /*
    等效于 ： ===
    private Integer detailCode ;
    private String holyBillCode;
    *
    * */

    private Integer quantity;
    private Float price;

   /* @ManyToOne(targetEntity = HolyBill.class)
    @JoinColumn(name = "hbCodeFk",referencedColumnName = "holyBollId")
    @MapsId("hbCodeFk")*/
    @ManyToOne()
    @JoinColumn(name = "hbCodeFk")
    // 让当前声明的java/id="hbCodeFk"取值 为当前列JoinColumn(name = "hbCodeFk")
    @MapsId("hbCodeFk")
    @JsonIgnore
    private HolyBill holyBill;

/**
 * Hibernate: create table HolyBill
 * (holyBollId integer not null, applier varchar(255), workTime datetime(6),
 * primary key (holyBollId)) engine=InnoDB
 * Hibernate: create table HolyDetail
 * (detailCode integer not null, hbCodeFk integer not null, price float, quantity integer,
 * primary key (detailCode, hbCodeFk)) engine=InnoDB
 * Hibernate: alter table HolyDetail add constraint FKlsxtq37h9guciltxs8e5xpw15
 * foreign key (hbCodeFk) references HolyBill (holyBollId)
 *
 * */
/**
 * Hibernate: create table HolyBill
 * (holyBollId integer not null, applier varchar(255), workTime datetime(6),
 * primary key (holyBollId)) engine=InnoDB
 * Hibernate: create table HolyDetail
 * (detailCode integer not null, hbCodeFk integer not null, price float, quantity integer,
 * primary key (detailCode, hbCodeFk)) engine=InnoDB
 * Hibernate: alter table HolyDetail
 * add constraint FKlsxtq37h9guciltxs8e5xpw15
 * foreign key (hbCodeFk) references HolyBill (holyBollId)
 * */

    @Override
    public String toString() {
        return MoreObjects.toStringHelper(this)
                .add("holyDetailId", holyDetailId)
                .add("quantity", quantity)
                .add("price", price)
                .toString();
    }
}
